package edu.pku.sei.transformation.editor.controller.commands.link;

import edu.pku.sei.transformation.editor.model.Compatiable;
import edu.pku.sei.transformation.editor.model.ModelType;

public class CompatibleCreateCommand extends
		AbstractLinkCreateCommand<Compatiable, ModelType, ModelType> {
	public CompatibleCreateCommand(Compatiable c, ModelType s) {
		super(c, s);
	}
	
	@Override
	public boolean canExecute() {
		if (super.canExecute()) {
			//circle found
			if (source.isCompatible(target))
				return false;
			else
				return true;
		} else {
			return false;
		}
	}

	@Override
	public void execute() {
		link.setSource(source);
		link.setTarget(target);
		source.getOutgoingCompatiables().add(link);
		target.getIncomingCompatiables().add(link);
	}

	@Override
	public void undo() {
		source.getOutgoingCompatiables().remove(link);
		target.getIncomingCompatiables().remove(link);
		link.setSource(null);
		link.setTarget(null);
	}
}
